﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Game.geodata;
using Game.model;

namespace Game.ai
{
    public class Ranger:DefaultAI
{
	/**
	 * Constructor for Ranger.
	 * @param actor NpcInstance
	 */
	public Ranger(NpcInstance actor):base(actor)
	{
		//super(actor);
	}
	
	/**
	 * Method thinkActive.
	 * @return boolean
	 */
	
	protected override bool thinkActive()
	{
		return base.thinkActive() || defaultThinkBuff(10);
	}
	
	/**
	 * Method onEvtAttacked.
	 * @param attacker Creature
	 * @param damage int
	 */
	
	protected override void onEvtAttacked(Creature attacker, int damage)
	{
		base.onEvtAttacked(attacker, damage);
		NpcInstance actor = getActor();
		if (actor.isDead() || (attacker == null) || (actor.getDistance(attacker) > 200))
		{
			return;
		}
		if (actor.isMoving)
		{
			return;
		}
		int posX = actor.getX();
		int posY = actor.getY();
		int posZ = actor.getZ();
		int old_posX = posX;
		int old_posY = posY;
		int old_posZ = posZ;
		int signx = posX < attacker.getX() ? -1 : 1;
		int signy = posY < attacker.getY() ? -1 : 1;
		int range = (int) (((0.71 * actor.calculateAttackDelay()) / 1000) * actor.getMoveSpeed());
		posX += signx * range;
		posY += signy * range;
		posZ = GeoEngine.getHeight(posX, posY, posZ, actor.getGeoIndex());
		if (GeoEngine.canMoveToCoord(old_posX, old_posY, old_posZ, posX, posY, posZ, actor.getGeoIndex()))
		{
			addTaskMove(posX, posY, posZ, false);
			addTaskAttack(attacker);
		}
	}
	
	/**
	 * Method createNewTask.
	 * @return boolean
	 */
	
	protected override bool createNewTask()
	{
		return defaultFightTask();
	}
	
	/**
	 * Method getRatePHYS.
	 * @return int
	 */
	
	public override int getRatePHYS()
	{
		return 25;
	}
	
	/**
	 * Method getRateDOT.
	 * @return int
	 */
	
	public override  int getRateDOT()
	{
		return 40;
	}
	
	/**
	 * Method getRateDEBUFF.
	 * @return int
	 */
	
	public override int getRateDEBUFF()
	{
		return 25;
	}
	
	/**
	 * Method getRateDAM.
	 * @return int
	 */
	
	public override int getRateDAM()
	{
		return 50;
	}
	
	/**
	 * Method getRateSTUN.
	 * @return int
	 */
	
	public override int getRateSTUN()
	{
		return 50;
	}
	
	/**
	 * Method getRateBUFF.
	 * @return int
	 */
	
	public override int getRateBUFF()
	{
		return 5;
	}
	
	/**
	 * Method getRateHEAL.
	 * @return int
	 */
	
	public override int getRateHEAL()
	{
		return 50;
	}
}

}
